<?php

namespace app\admin\validate;

use think\Validate;

class Product extends Validate
{
    protected $rule = [
        'sku' => 'require|max:255',
        'computing_unit' => 'require|max:5',
        'freight_tag' => 'max:1',
        'model' => 'max:2',
        'cname' => 'require|max:255',
        'code' => 'require|max:255',
        'category' => 'max:255',
        'condition' => 'require|in:0,1',
        'cost' => 'float|egt:0',
        'sales_rate' => 'float|egt:0',
        'freight_price' => 'float|egt:0',
        'is_advance' => 'in:0,1',
        'status' => 'require|in:0,1',
        'model_id' => 'require|integer|gt:0',
        'min_num' => 'integer|egt:0',
        'id' => 'integer|gt:0',
        'power' => 'require|integer|egt:0',
        'weight' => 'float|egt:0',
        'gross_weight' => 'float|egt:0',
        'transport_weight' => 'float|egt:0',
        'dimensions' => 'float|egt:0',
        'gross_dimensions' => 'float|egt:0',
        'volume' => 'float|egt:0',
        'hashrate' => 'require|float|egt:0',

        'advance_ratio' => 'float|egt:0',
        'has_powersource' => 'require|in:0,1',
        'has_powerline' => 'require|in:0,1',
        'memory_size' => 'integer|gt:0',
        'chip_number' => 'integer|gt:0',
        'powerline_standards' => 'integer|requireIf:has_powerline,1|gt:0',
        'algorithm' => 'require',
    ];

    protected $scene = [
        'search' => ['sku' => 'max:255', 'cname' => 'max:255'],
        'delete' => ['ids' => 'require|array|checkIds'],
        'show' => ['id' => 'require'],
        'create' => [
            'cname',
            'code',
            'category_name',
            'has_powersource',
            'has_powerline',
            'condition',
            'status',
            'computing_unit',
            'freight_tag',
            'model',
            'power',
            'weight',
            'gross_weight',
            'transport_weight',
            'dimensions',
            'gross_dimensions',
            'volume',
            'hashrate',
            'min_num',
            'sales_rate',
            'advance_ratio',
            'cost',
            'memory_size',
            'chip_number',

            'powerline_standards',
            'model_id',
            'algorithm'
        ],
        'save' => [
            'cname',
            'code',
            'category_name',
            'has_powersource',
            'has_powerline',
            'condition',
            'status',
            'id',
            'computing_unit',
            'freight_tag',
            'model',
            'power',
            'weight',
            'gross_weight',
            'transport_weight',
            'dimensions',
            'gross_dimensions',
            'volume',
            'hashrate',
            'min_num',
            'sales_rate',
            'advance_ratio',
            'cost',
            'memory_size',
            'chip_number',

            'powerline_standards',
            'model_id',
            'algorithm'
        ],
        'resource' => ['field'],
        'update' => ['id']
    ];

    protected $message = [
        'memory_size.integer' => '内存必须为整数',
        'memory_size.gt' => '内存必须大于0',
        'chip_number.integer' => '芯片数量必须为整数',
        'chip_number.gt' => '芯片数量必须大于0',
        'billing_weight.require' => '计费重量不能为空',
        'billing_weight.float' => '计费重量必须为数字',
        'billing_weight.gt' => '计费重量必须大于0',
        'powerline_standards.requireIf' => '电源线标准不能为空',
        'powerline_standards.integer' => '电源线标准必须为整数',
        'powerline_standards.gt' => '电源线标准必须大于0',
        'model_id.require' => '型号不能为空',
        'model_id.integer' => '型号必须为整数',
        'model_id.gt' => '型号必须大于0',
        'algorithm.require' => '支持算法不能为空',
        'hashrate.require' => '算力不能为空',
        'computing_unit.require' => '算力单位不能为空',
        'power.require' => '功率不能为空',
    ];
}
